package demo1;

import java.util.concurrent.*;
//使用线程池
public class test {
    public static void main(String[] args) {
        ExecutorService service= Executors.newFixedThreadPool(10);
        //线程池对象不是new出来的，而是通过专门的方法返回对象
        for (int i = 0; i < 10; i++) {
            int id=i;
            service.submit(new Runnable() {
                @Override
                public void run() {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    System.out.println("Task"+id+"is completed");
                }
            });
        }
service.shutdown();
    }
}
